package com.yunhe.authority.service.company.impl;

import com.yunhe.authority.domain.company.CompanySupportingInfo;
import com.yunhe.authority.repository.company.CompanySupportingInfoRepository;
import com.yunhe.authority.service.company.CompanySupportingInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: CompanySupportingInfoServiceImpl
 * @Description:
 * @author: GongDaCheng
 * @Date: 10:34 2021/7/14
 */
@Service
public class CompanySupportingInfoServiceImpl implements CompanySupportingInfoService {

    private static final Logger logger = LoggerFactory.getLogger(CompanySupportingInfoServiceImpl.class);


    @Autowired
    CompanySupportingInfoRepository companySupportingInfoRepository;

    @Override
    public CompanySupportingInfo save(Long companyId, CompanySupportingInfo companySupportingInfo) {
        CompanySupportingInfo newCSInfo = companySupportingInfoRepository.save(companySupportingInfo);
        CompanySupportingInfo getByCompanyId = companySupportingInfoRepository.getByCompanyId(companyId);
        if (getByCompanyId == null){
            Long csInfoId = newCSInfo.getId();
            companySupportingInfoRepository.bindCompany(companyId,csInfoId);
        }

        return newCSInfo;
    }


    @Override
    public CompanySupportingInfo getByCompanyId(Long companyId) {
        CompanySupportingInfo newCSInfo = companySupportingInfoRepository.getByCompanyId(companyId);
        return newCSInfo;
    }

    @Override
    public void unbindAndDelete(Long companyId) {
        companySupportingInfoRepository.unbindAndDelete(companyId);
    }


}
